import sys

def socketListen(socket,fromName,gpg):
    run=True
    while run:
        gpgdata=socket.recv(1024).decode()
        data=str(gpg.decrypt(gpgdata))
        if (data=="/quit"):
            print(fromName + " has disconnected, closing listener\n")
            run=False
            sys.exit()
        if not data: sys.exit(0)
        print(fromName + ":" + data)
    print("Closing listener")

def UDPListen(socket,fromName,gpg):
    run=True
    while run:
        gpgdata,address=socket.recvfrom(1024)
        gpgdata=gpgdata.decode()
        data=str(gpg.decrypt(gpgdata))
        if (data in ["/quit","/q"]):
            print(fromName + " has disconnected, closing listener\n")
            run=False
            sys.exit()
        if not data: sys.exit(0)
        print(fromName + ":" + data)
    print("Closing listener")
